package com.yeung.exam;

import java.util.Arrays;
import java.util.Scanner;

public class 逆序对 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int q = scanner.nextInt();
        int count = (int) Math.pow(2, q);
        long[] numbers = new long[count];
        int index = 0;
        while (index < count) {
            numbers[index] = scanner.nextInt();
            index++;
        }
        int m = scanner.nextInt();
        while (m > 0) {
            int nums = 0;
            int qi = scanner.nextInt();
            qi= (int) Math.pow(2.0,qi);
            //每个qi一组, 反转,  计算每一组的逆序数
            int start = 0;
            int end = start + qi;

            while (true) {
                long[] part = Arrays.copyOfRange(numbers, start, end);
                //fan zhaun
                long[] clone = part.clone();
                for (int i = 0; i < part.length; i++) {
                    clone[i] = part[part.length - 1 - i];
                }
                //qiu ni xu
                for (int i = 0; i < clone.length; i++) {
                    for (int j = 0; j < i; j++) {
                        if (clone[j] > clone[i]) nums++;
                    }
                }
                //geng xin start
                start = end;
                if (start == numbers.length - 1) break;
                if (end + qi > numbers.length - 1)
                    end = numbers.length - 1;
                else
                    end += qi;

            }
            System.out.println(nums);
        }
        m--;
    }
}
